package com.gqz.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {

    private boolean success = false;

    private String message = "操作失败!";

    private String code = "400";

    private Object data;

    public static JsonResult ok() {
        return ok(null);
    }

    public static JsonResult ok(Object data) {
        return ok("操作成功!", data);
    }

    public static JsonResult ok(String message, Object data) {
        return new JsonResult(true, message, "200", data);
    }

    public static JsonResult fail() {
        return fail("操作失败!");
    }

    public static JsonResult fail(String message) {
        return new JsonResult(false, message, "400", null);
    }

    public static JsonResult error(String message) {
        return new JsonResult(false, message, "500", null);
    }

    public static JsonResult custom(boolean success, String message, String code, Object data) {
        return new JsonResult(success, message, code, data);
    }

    public static JsonResult toAjax(boolean result) {
        return result ? ok() : fail();
    }
}
